//
//  EJViewController.m
//  EJCommentKit
//
//  Created by 15093319898@163.com on 11/29/2021.
//  Copyright (c) 2021 15093319898@163.com. All rights reserved.
//

#import "EJViewController.h"
#import "EJCommentInputView.h"
#import "EJCommentMenuView.h"
#import <EJTools/EJProgressHUD.h>

@interface EJViewController ()<EJCommentInputViewDelegate, EJCommentMenuViewDelegate>

@property (nonatomic, strong) EJCommentInputView * commentView;

@property (nonatomic, strong) EJCommentMenuView * commentMenu;

@end

@implementation EJViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}


- (IBAction)handleClickInputButton:(UIButton *)sender {
    // 评论框
    [self.view.window addSubview:self.commentView];
//    _commentView.commentBar.textView.placeholder = @"说点什么...";
//    [_commentView.commentBar.textView becomeFirstResponder];
        
    [_commentView beginOnceInput];
}

- (IBAction)handleTapLabel:(UITapGestureRecognizer *)sender {
    UIWindow * window = [UIApplication sharedApplication].delegate.window;
    CGPoint point = [sender locationInView:sender.view];
    
    point = [sender.view convertPoint:point toView:window];
    
    // 评论操作项
    self.commentMenu.menuTitles = @[@"回复", @"复制", @"删除", @"回复1", @"复制1", @"删除1"];
    [_commentMenu showInPoint:point];
    
}

#pragma mark - EJCommentInputViewDelegate
- (void)ej_commentInputViewDidClickSendWithContent:(NSString *)content {
    content = [content stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
    if ([content length] == 0) {
        [EJProgressHUD showAlert:@"请输入有效评论" forView:[UIApplication sharedApplication].delegate.window];
        return;
    }
}

#pragma mark - EJCommentMenuViewDelegate
- (void)ej_commentMenuViewDidHide {
    
}

- (void)ej_commentMenuViewDidClickAtIndex:(NSUInteger)index {
    
}

#pragma mark - getter or setter
- (EJCommentInputView *)commentView {
    if (!_commentView) {
        _commentView = [[EJCommentInputView alloc] initWithWordLimitType:EJ_Comment_WordLimitType_Alert maxCount:200];
        _commentView.delegate = self;
    }
    return _commentView;
}

- (EJCommentMenuView *)commentMenu {
    if (!_commentMenu) {
        _commentMenu = [[EJCommentMenuView alloc] init];
        _commentMenu.delegate = self;
    }
    return _commentMenu;
}

@end
